"use strict";
cc._RF.push(module, '32ac7U3+OdFpJMImIy13br0', 'ScreenAdapter');
// eazax-ccc/components/ScreenAdapter.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var EventManager_1 = require("../core/EventManager");
var _a = cc._decorator, ccclass = _a.ccclass, executionOrder = _a.executionOrder;
/**
 * 屏幕适配组件
 * @see ScreenAdapter.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/ScreenAdapter.ts
 * @version 20210504
 */
var ScreenAdapter = /** @class */ (function (_super) {
    __extends(ScreenAdapter, _super);
    function ScreenAdapter() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ScreenAdapter.prototype.onLoad = function () {
        this.init();
    };
    ScreenAdapter.prototype.onEnable = function () {
        this.adapt();
    };
    ScreenAdapter.prototype.init = function () {
        var _this = this;
        // 设置游戏窗口变化的回调（仅 Web 平台有效）
        cc.view.setResizeCallback(function () { return _this.onResize(); });
    };
    /**
     * 窗口变化回调
     */
    ScreenAdapter.prototype.onResize = function () {
        // 由于 setResizeCallback 只能设置一个回调
        // 使用事件系统发送一个特定事件，让其他组件也可以监听到窗口变化
        EventManager_1.default.emit('view-resize');
        // 适配
        this.adapt();
    };
    /**
     * 适配
     */
    ScreenAdapter.prototype.adapt = function () {
        // 实际屏幕比例
        var winSize = cc.winSize, screenRatio = winSize.width / winSize.height;
        // 设计比例
        var designResolution = cc.Canvas.instance.designResolution, designRatio = designResolution.width / designResolution.height;
        // 判断实际屏幕宽高比
        if (screenRatio <= 1) {
            // 此时屏幕高度大于宽度
            if (screenRatio <= designRatio) {
                this.setFitWidth();
            }
            else {
                // 此时实际屏幕比例大于设计比例
                // 为了保证纵向的游戏内容不受影响，应使用 fitHeight 模式
                this.setFitHeight();
            }
        }
        else {
            // 此时屏幕高度小于宽度
            this.setFitHeight();
        }
    };
    /**
     * 适配高度模式
     */
    ScreenAdapter.prototype.setFitHeight = function () {
        var canvas = cc.Canvas.instance;
        canvas.fitHeight = true;
        canvas.fitWidth = false;
    };
    /**
     * 适配宽度模式
     */
    ScreenAdapter.prototype.setFitWidth = function () {
        var canvas = cc.Canvas.instance;
        canvas.fitHeight = false;
        canvas.fitWidth = true;
    };
    ScreenAdapter = __decorate([
        ccclass,
        executionOrder(-999)
    ], ScreenAdapter);
    return ScreenAdapter;
}(cc.Component));
exports.default = ScreenAdapter;

cc._RF.pop();